/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// pmessage.hpp - PegMessage and PegMessageQueue type definition.
//
// Author: Kenneth G. Maxwell
//
// Copyright (c) 1997-2000 Swell Software 
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software
// is strictly prohibited.
//
// Notes:
//
//     Message wType fields are allocated thus:
//
//      0x0000  - 0x00ff            pre-defined messages PM_xxxx
//      0x0100  - 0x3fff            reserved
//      0x4000  - 0x7fff            user-defined message area
//      0x8000  - 0xffff            signals
//
// 
//
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef _PEGMESSAGE_
#define _PEGMESSAGE_

/*--------------------------------------------------------------------------*/
// Standard PEG generated message types:

enum PegSystemMessage {
    PM_ADD = 1,
    PM_REMOVETHING,
    PM_DESTROY,
    PM_SIZE,
    PM_MOVE,
    PM_CLOSE,
    PM_HIDE,
    PM_SHOW,
    PM_POINTER_MOVE,
    PM_LBUTTONDOWN,
    PM_LBUTTONUP,
    PM_RBUTTONDOWN,
    PM_RBUTTONUP,
    PM_DRAW,
    PM_CURRENT,
    PM_NONCURRENT,
    PM_GAINED_KEYBOARD,
    PM_LOST_KEYBOARD,
    PM_LANGUAGE_CHANGE,
    PM_POINTER_ENTER,
    PM_POINTER_EXIT,
    PM_EXIT,
    PM_ADDICON,
    PM_BEGIN_MOVE,
    PM_PARENTSIZED,
    PM_VSCROLL,
    PM_HSCROLL,
    PM_MAXIMIZE,
    PM_MINIMIZE,
    PM_RESTORE,
    PM_CLOSE_SIBLINGS,
    PM_TIMER,
    PM_KEY,
    PM_KEY_RELEASE,
    PM_CUT,
    PM_COPY,
    PM_PASTE,
    PM_SLIDER_DRAG,
    PM_MWCOMPLETE,
    PM_DIALOG_NOTIFY,
    PM_DIALOG_APPLY,
    PM_MOVE_FOCUS,
    PM_DRAW_NOTIFY,
    PM_RESOURCE_CHANGE,
    PM_SURFACE_CHANGE,
    PM_OPENGL_REFRESH,
   #if defined(PEG_OPERA_SUPPORT)
    PM_GOGI_OPERA_EVENT,
   #endif  // PEG_OPERA_SUPPORT
    PM_MISC_TOUCH_MOVE,
    PM_MISC_TOUCH_DOWN,
    PM_MISC_TOUCH_UP,
    PM_MISC_TOUCH2_MOVE,
    PM_MISC_TOUCH2_DOWN,
    PM_MISC_TOUCH2_UP,
    PM_MISC_TOUCH_CAL,
    PM_MISC_KEY,
    PM_MISC_KEY_RELEASE,
};

const PEGUINT FIRST_SIGNAL          = 0x8000;
const PEGUINT FIRST_USER_MESSAGE    = 0x4000;

class PegThing;             // forward reference

/*--------------------------------------------------------------------------*/
// PegMessage definition:
// New fields may be added as needed by the user.

struct PegMessage
{
    public:
        PegMessage() 
        {
            pNext = NULL;
            pSource = NULL;
            pTarget = NULL;
        }

        PegMessage(PEGUSHORT Val) 
        {
            pNext = NULL; 
            pSource = NULL;
            pTarget = NULL;
            Type = Val;
        }

        PegMessage(PegThing *Target, PEGUSHORT Val)
        {
            pNext = NULL;
            pSource = NULL;
            pTarget = Target;
            Type = Val;
        }

        PegThing *pSource;        
        PegThing *pTarget;      // address of target object
        PEGUSHORT Type;
        PEGUSHORT Param;

        union
        {
            PegRect    Rect;
            PegPoint   Point;
            PEGLONG    ExtParams[2];  // signed params

            // the following fields are never used by PEG, but they can
            // be used by applications sending user-defined messages:

            void       *pData;
            PEGLONG    UserLong[4];
            PEGULONG   UserULong[4];
            PEGSHORT   UserShort[8];
            PEGUSHORT  UserUShort[8];
            PEGUBYTE   UserUByte[16];
        };

        PegMessage *pNext;
};


/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// PegMessageQueue definition:
// New fields may be added as needed by the user.

class PegMessageQueue
{


    public:

        PegMessageQueue(void);
        ~PegMessageQueue();

        void Fold(PegMessage *pIn);
       #ifdef PEG_MULTITHREAD
        void Fold(PegMessage *pIn, PEG_QUEUE_TYPE pQueue);
       #endif

        PEGBOOL IsEmpty(void);
        void Pop(PegMessage *);
        void Purge(PegThing *Del, PEGUSHORT Type = 0, PEGUSHORT Param = 0);
        PEGBOOL Push(PegMessage *);
        PEGBOOL Push(PegMessage &In) {return Push(&In);}

    private:

       #if defined(PEG_STANDALONE_MESSAGE_QUEUE) || defined(PEGINTEGRITY)

        // The RTOS integrations usually replace the standalone
        // PEG message queue implementation, so we don't need these
        // member variables.

        PegMessage *mpFirst;
        PegMessage *mpLast;
        PegMessage *mpFree;
        PegMessage *mpFreeEnd;
       #endif
};

#endif






